<template>
    <div>
        <div>
            <el-button type="primary" size="medium" @click="showOfficalComment('')">发布官方点评</el-button>
        </div>

        <!-- 列表 -->
        <el-table
            :data="tableData"
            style="width: 100%">
            <el-table-column
                prop="phone"
                label="评论内容"
                width="120"
                >
                <template slot-scope="scope">
                    <div @click.stop="showComment(scope.row)">
                        <span style="cursor:pointer;color:#409EFF"  >{{scope.row.content}}</span>
                    </div>
                </template>
            </el-table-column>
                   
            <el-table-column
                prop="comment_like_num"
                label="点赞"
                width="100"
                >
            </el-table-column>
            <el-table-column
                prop="created_at"
                label="发布时间"
                width="200"
                >
            </el-table-column>
            <el-table-column label="操作" width='150'>
                <template slot-scope="scope">
                    <el-button type='text' @click="showOfficalComment(scope.row.id)" >编辑</el-button>
                    <el-button type='text' @click="deleteComment(scope.row.id)" >删除</el-button>
                </template>
            </el-table-column>
            
        </el-table>
        <el-col :span="24" class="footer-bar">
			<div class="page-code">
				<el-pagination
					background
					:page-size="16"
					layout="prev, pager, next"
					:total="totalPage"
					@current-change="pageChange"
						>
				</el-pagination>
			</div>
    </el-col>
    <!-- 列表end -->

        <!-- 官方评论弹窗 -->
		<el-dialog title="官方评论" :visible.sync="officalCommentVisible" @close="initData">
            <el-input type="textarea" v-model="comment"></el-input>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="setExpertOfficialComment">发布</el-button>
            </div>
		</el-dialog>
        <!-- 官方评论弹窗end -->

        <!-- 评论弹窗 -->
		<el-dialog title="评论" :visible.sync="commentVisible" @close="initData">
            <div>{{comment}}</div>
		</el-dialog>
        <!-- 评论弹窗end -->
    </div>
</template>
<script>
export default {
    name:'member',
    data() {
        return {
            id:'',
            comment:'',
            commentVisible:false,
            officalCommentVisible:false,//编辑官方评论弹窗状态
            commentId:'',
            
            tableData: [{}],
            page:1,
            totalPage:0    
        }
    },
    watch: {

    },
    methods: {
        search(){
            this.page=1;
            this.getExpertOfficialCommentList()
        },
        async getExpertOfficialCommentList(){
            //获取会员列表
            let params={
                id:this.id,
                page:this.page,
                limit:16
            }
            let res=await this.$api.getExpertOfficialCommentList(
                params);
            if(res.data.level=='success'){
                this.tableData=res.data.data;
                this.totalPage=res.data.page_info.total;
            }
        },
        pageChange(e){
			//翻页
			this.page=e;
			this.getExpertOfficialCommentList();
        },
        async deleteComment(id){
            //删除评论
            let judge=null;
            let tit='删除该评论?'
            try {
              judge=  await this.$confirm(tit, '提示', {
				confirmButtonText: '确定',
				cancelButtonText: '取消',
				type: 'warning'
                })
            } catch (error) {
                judge='cancel'
            }
            if(judge=='confirm'){
                this.delExpertOfficialComment(id)
            }
            console.log(judge)
        },
        async delExpertOfficialComment(id){
            let res=await this.$api.delExpertOfficialComment({id:id})
            if(res.data.level=='success'){
                this.$message.success(res.data.message);            
                this.getExpertOfficialCommentList();
            }else{
                this.$message.error(res.data.message);
            }
        },

        async showOfficalComment(id){
            //填写官方评论
            if(id){
                this.commentId=id;
                let res=await this.$api.getExpertOfficialCommentDetail({id:id});
                if(res.data.level=='success'){
                    this.comment=res.data.data.content
                }else{
                    this.$message.error(res.data.message)
                }
            }
            this.officalCommentVisible=true
        },
        showComment(scope){
            //显示用户评论
            this.comment=scope.content
            this.commentVisible=true
        },
        async setExpertOfficialComment(){
            let params={
                id:this.commentId,
                expert_id:this.id,
                content:this.comment
            }
            let res=await this.$api.setExpertOfficialComment(params)
            if(res.data.level=='success'){
                this.$message({
                    type:'success',
                    message:res.data.message
                })
                this.officalCommentVisible = false;
                this.getExpertOfficialCommentList();
                
            }else{
                this.$message({
                    type:'error',
                    message:res.data.message
                })

                
            }
        },
        initData(){
            this.comment='';
            this.commentId=''
        }

    },
    mounted() {
        this.id=this.$route.query.id
        this.getExpertOfficialCommentList()
    },
}
</script>
<style lang="scss" scoped>
    .screen{
          margin-top: -10px !important;
      }
      .action-bar-wrapper{
          position: sticky;
            z-index: 1;
            top:-10px;
      }
    .action-bar{
			background-color: #f2f2f2;
            
			height: 60px;
			margin: 10px 0px;
			box-sizing: border-box;
			display: flex;
			align-items: center;
			padding-left: 20px;
			.action-bar-input{
				width: 250px;
				margin-right: 14px;
      }
      .task-form-text{
				color: #666666;
			}
		}
		.el-table-style{
			width: 100%;
			border: 1px solid #f2f2f2;
		}
		.footer-bar{
			display: flex;
			justify-content: space-between;
			align-items: center;
			background: #f2f2f2;
			padding: 8px;
			margin: 10px 0px;
			box-sizing: border-box;
		}
		.dialog-footer{
			text-align: center;
		}
		.executorList{
			display: flex;
			flex-wrap: wrap;
			div{
				margin:10px;
				border:1px solid #eee;
				border-radius: 5px;
				padding:5px 10px;
			}
		}
</style>